from flask import Flask
from flask_restful import reqparse, Resource, Api

app = Flask(__name__)
api = Api(app)

"""
required: 描述请求是否一定要携带对应参数，默认值为False
    True, 强制要求携带, 若未携带，则校验失败，向客户端返回错误信息，状态码400
    False,不强制要求携带, 若不强制携带，在客户端请求未携带参数时，取出值为None
    
{
    "message": {
        "name": "miss name params"
    }
}
"""
class UserResource(Resource):
    def get(self):
        rp = reqparse.RequestParser()
        rp.add_argument('name', required=True, help='miss name params')
        args = rp.parse_args()
        print(args)
        return {"name":"lisi"}


api.add_resource(UserResource, '/user')


if __name__ == '__main__':
    app.run(debug=True)


